import os
import threading
import ConfigParser # parse the conf file

# Loop that read the sound.txt file
# to play that sound with mplayer in a thread
# made by start.py

# directory in conf file
config = ConfigParser.RawConfigParser()
config.read('lolita3dbot.conf')

# The loop check if there is a sound.txt and read the title!
# And you can have multiple sounds at the same time : cool !
def MyTimer(tempo = 1.0):
        threading.Timer(tempo, MyTimer, [tempo]).start()
        print "right in timer !"
	# Read delete and play the sound in sound.txt
        if os.path.exists('sound.txt'):
		print "open sound txt"
		f = open("sound.txt", "r")
		text = f.read()
		f.close()
		os.remove('sound.txt')
		# check sound file exist
		directory = config.get('sound', 'directory')
		print "play" + directory + text
		# launch mplayer easier than vlc
		os.system("mplayer " + directory + text)

# Activate timer for sound
MyTimer(4.0)

